<?php


namespace App\backend\services;


use App\backend\models\GoodsModel;
use App\Exceptions\InvalidRequestException;

class GoodsDepotServices
{

    /**
     * 获取 - 商品回收站列表
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function getList($data)
    {
        $page = !isset($data['page']) ? 1 : $data['page'];unset($data['page']);
        $limit = !isset($data['limit']) ? 10 : $data['limit'];unset($data['limit']);

        $where_data = [];
        if (isset($data['title']) && !empty($data['title'])) {
            $where_data[] = ['title','like',"%{$data['title']}%"];
        }
        if (isset($data['type']) && !empty($data['type'])) {
            $where_data[] = ['type','=',$data['type']];
        }
        if (isset($data['categorys']) && !empty($data['categorys'])) {
            $where_data[] = ['categorys','=',$data['categorys']];
        }
        if (isset($data['group']) && !empty($data['group'])) {
            $where_data[] = ['group','=',$data['group']];
        }

        $list = GoodsModel::depot_listed($page, $limit, $where_data);
        if (empty($list)) {
            throw new InvalidRequestException(10009);
        }

        return $list;
    }

    /**
     * 恢复 - 商品回收站
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function goodsRestore($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id']= isset($data['goods_id']) && !empty($data['goods_id']) ? $data['goods_id'] : 0;unset($data['goods_id']);
        $list = GoodsModel::updateds($data, ['status' => 0]);
        return $list;
    }

    /**
     * 永久删除 - 商品回收站
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function goodsDelete($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id']= isset($data['goods_id']) && !empty($data['goods_id']) ? $data['goods_id'] : 0;unset($data['goods_id']);
        $list = GoodsModel::updateds($data, ['status' => 8]);
        return $list;
    }

}
